<!DOCTYPE html>
<html lang="en">
<include file="./Application/Home/View/Layout/head.html" />

        <link href="__PUBLIC__/assets/bootstrap/css/select2.css" rel="stylesheet" />		
        <link href="__PUBLIC__/assets/bootstrap/css/jquery.dataTables.min.css" rel="stylesheet">
        <style type="text/css">
 .Alertmessage{
	text-align: center;
    color: red;
 }
 #tips{float: left; font-size: 12px; width: 400px; height: 25px; margin: 4px 0 0 20px;}
 #tips span{float: left; width: 40px; height: 30px; line-height: 30px; color: #fff; overflow:hidden; margin-right: 10px; background: #D7D9DD;  text-align: center; }
 #tips .s1{background: #F45A68;}/*红色*/
 #tips .s2{background: #fc0;}/*橙色*/
 #tips .s3{background: #cc0;}/*黄色*/
 #tips .s4{background: #14B12F;}/*绿色*/
       </style>

    <body>
        <block name="header">
           <include file="block/header"/>
        </block>
        <section>
            <div class="mainwrapper">
			   <block name="left">
			   <include file="block/left" />
               </block>
                
                <div class="mainpanel">
                    <div class="contentpanel">
                       
                       	<div class="col-md-12">
                                <form id="basicForm" method="post" action="userAdd">
                                <div class="panel panel-default">
                                    <div class="panel-heading">
                                        <div class="panel-btns">
                                            <a href="#" class="panel-minimize tooltips" data-toggle="tooltip" title="Minimize Panel"><i class="fa fa-minus"></i></a>
                                            <a href="#" class="panel-close tooltips" data-toggle="tooltip" title="Close Panel"><i class="fa fa-times"></i></a>
                                        </div><!-- panel-btns -->
                                        <h4 class="panel-title">用户添加</h4>
                                    </div><!-- panel-heading -->
                                    <div class="panel-body">
                                        <div class="row">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">用户名 <span class="asterisk">*</span></label>
                                                <div class="col-sm-6">
                                                    <input type="text" id="username" name="username" class="form-control" placeholder="用户名" required />
                                                </div>
                                            </div><!-- form-group -->
                                          
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">密码 <span class="asterisk">*</span></label>
                                                <div class="col-sm-3">
                                                    <input type="password" id="password" name="password" class="form-control" placeholder="密码" required />
                                                    <input type="hidden" id="pwdlevel" name="pwdlevel" value="0">
                                                </div>
                                                <div id="tips" class="col-sm-3">
                                                    <span>弱</span>
                                                    <span>中</span>
                                                    <span>强</span>
                                                    <span>很强</span>
                                                </div>
                                            </div><!-- form-group -->
                                          
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">用户权限</label>
                                                <div class="col-sm-6">
                                                      <div class="ckbox ckbox-primary col-sm-2">
                                                        <input type="checkbox" value="1" id="int_search" name="can">
	                                                    <label for="int_search">查询</label>
	                                                  </div>　
	                                                  <div class="ckbox ckbox-primary col-sm-2">
	                                                    <input type="checkbox" value="1" id="int_manage" name="can">
	                                                    <label for="int_manage">管理</label>
	                                                  </div>
	                                                  <div class="ckbox ckbox-primary col-sm-2">
	                                                    <input type="checkbox" value="1" id="int_audit" name="can">
	                                                    <label for="int_audit">审计</label>
	                                                  </div>
                                                    </div>
                                              </div><!-- form-group -->
                                            
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">有权号码<span class="asterisk">*</span></label>
                                                <div class="col-sm-6">
                                                    <textarea rows="5" id="privilege" name="privilege" class="form-control" placeholder="有权号码，指用户有权查看录音的号码。此项留空则可查看所有号码的录音。 
多个号码用逗号隔开，系统将自动过滤非数字字符。" required></textarea>
                                                </div>
                                            </div><!-- form-group -->
                                            
                                            <div class="form-group">
	                                            <label class="col-sm-2 control-label">工作站<span class="asterisk">*</span></label>
	                                            <div class="col-sm-6">
	                                            <foreach name="station" item="list">
	                                                <div class="ckbox ckbox-primary">
	                                                    <input type="checkbox" id="site_{$list.n_sid}" class="selectStation" value="{$list.n_sid}" name="site" required="">
	                                                    <label for="site_{$list.n_sid}">{$list.v_sname}</label>
	                                                </div><!-- rdio -->
	                                             </foreach>
	                                             <div class="ckbox ckbox-primary">
	                                                    <input type="checkbox" value="f"  id="checkSiteAll" name="checkSiteAll">
	                                                    <label for="checkSiteAll">全选/全否</label>
	                                              </div>   
	                                                
	                                            </div>
                                            </div>
                                            
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">备注信息<span class="asterisk">*</span></label>
                                                <div class="col-sm-6">
                                                    <textarea rows="5" id="remark" name="remark" class="form-control" placeholder="备注信息" required></textarea>
                                                </div>
                                            </div><!-- form-group -->
                                        </div><!-- row -->
                                        <div class="modal-footer col-sm-6">
									        <a href="/home/Account/userManage" class="btn btn-default" data-dismiss="modal">取消</a>
									        <button type="button" class="btn btn-primary submit">添加</button>
									    </div>
                                    </div><!-- panel-body -->
                           
                                </div><!-- panel -->
                                </form>
                                
                            </div><!-- col-md-6 -->
                           
                            
					      
                        </div><!-- panel -->
                      
                        <div style="clear:both"></div>
                    </div><!-- contentpanel -->
                </div><!-- mainpanel --><!-- mainpanel -->
            </div><!-- mainwrapper -->
            
        <!-- 告警模态框 -->
		<div class="modal fade" id="alertModel" tabindex="-1" role="dialog" aria-labelledby="myAlert">
		  <div class="modal-dialog" role="document" style="width:450px">
		    <div class="modal-content" >
		      <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
		        <h4 class="modal-title" id="myAlert" style="text-align: center;">提示</h4>
		      </div>
		      <div class="modal-body">
		        <div class="inner">
		        	<h4 class="Alertmessage"> </h4>
		        </div>
		        
		      </div>
		      <div class="modal-footer">
		        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
		        <button type="button" class="btn btn-primary ok">确定</button>
		      </div>
		    </div>
		  </div>
		</div>
        </section>
		
        <script src="__PUBLIC__/assets/bootstrap/js/jquery-1.11.1.min.js"></script>
        <script src="__PUBLIC__/assets/bootstrap/js/bootstrap.min.js"></script>
        <script src="__PUBLIC__/assets/bootstrap/js/custom.js"></script>
        


<script type="text/javascript">
$(document).ready( function () {
    var canManage = "{$canManage}";
    if(canManage == 0){
        $('#alertModel2').modal('show');
        $('.Alertmessage').html('没有管理权限，请联系管理员')
        return;
    }
    var spanDoms = $('#tips').find("span");
    $("#password").keyup(function(){
        //获取用户输入的密码,然后判断其强度 返回0 或者 1 2 3 4
        var index = checkPassWord(this.value);
        for(var i = 0; i <spanDoms.length; i++){
            spanDoms[i].className = "";
            //清空span标签所有的class样式
            if(index){
                //0 代表false 其余代表true 
                $('#tips').find("span").eq(index-1).addClass("s"+index)
                $("#pwdlevel").val(index)
            }
        }
    });

  $('.submit').click(function(){
      var canManage = "{$canManage}";
      if(canManage == 0){
          $('#alertModel2').modal('show');
          $('.Alertmessage').html('没有管理权限，请联系管理员')
          return;
      }
	  
	   var username = $('#username').val()
	   var password = $('#password').val()
	   var privilege = $('#privilege').val();
	   var remark = $('#remark').val();
       var canItems = -1
       var val = 0 
    	   $("input[name='can']").each(function(){
               if($(this).is(":checked"))
               {
            	   val = 1
               }
               else{
            	   val = 0
               }
               
               if(canItems ==  -1){
            	   canItems = val
			   }
			  else{
				  canItems = canItems +","+ val
				}
             });
        
       var stationid =""
    		 $('input[name="site"]:checked').each(function(){ 
    			 if(stationid ==""){
    				 stationid = $(this).val()
    			 }
    			 else{
    				 stationid = stationid +","+ $(this).val()
    			 }
       }); 
       if(username ==''){
    	   $('#alertModel').modal('show');
   		   $('.Alertmessage').html('用户名不能为空') 
   		   return;
       } 
	   if(password =='' || (password.length <6 || password.length >12)){ 
			$('#alertModel').modal('show');
   		   $('.Alertmessage').html('请输入6~12位密码') 
   		   return;
	   }
	   if($("#pwdlevel").val() == 1 || password.length < 5){
	       $('#alertModel').modal('show');
   		   $('.Alertmessage').html('密码强度太弱，请重新设置') 
   		   return;
	   }
      var url = "userAdd" 
	  $.ajax({
				type:"POST",
				url:url,
				data:{
					username:username,password:password,canItems:canItems,privilege:privilege,stationid:stationid,remark:remark	
				},
				success: function(data){
					if(data.code){
						$('.Alertmessage').css("color",'#1fb5ad');
					}
					else{
						$('.Alertmessage').css("color",'red');
					}
				    $('#alertModel').modal('show');
		   		    $('.Alertmessage').html(data.message)
				}
	 })





  $("#checkSiteAll").click(function() {
	    var state = $("#checkSiteAll").prop("checked");
	    if(state == true) {
	        $(".selectStation").prop("checked", "checked");
	    } else {
	        $(".selectStation").prop("checked", "");
	    }
	});
  
}) 

$('.ok').click(function(){
   $('#alertModel').modal('hide');
   window.location.href="/home/Account/userManage"
})

//校验密码强度
    function checkPassWord(value){

        // 0： 表示第一个级别 1：表示第二个级别 2：表示第三个级别
        // 3： 表示第四个级别 4：表示第五个级别
        var modes = 0;
        if(value.length < 3){
            //最初级别
            return modes;
        };

        if(/\d/.test(value)){
            //如果用户输入的密码 包含了数字
            modes++;
        }
        if(/[a-z]/.test(value)){
            //如果用户输入的密码 包含了小写的a到z
            modes++;
        }
        if(/[A-Z]/.test(value)){
            //如果用户输入的密码 包含了大写的A到Z
            modes++;
        }
        if(/\W/.test(value)){
            //如果是非数字 字母 下划线
            modes++;
        }
        switch(modes){
            case 1 :
                return 1;
                break;
            case 2 :
                return 2;
                break;
            case 3 :
                return 3;
                break;
            case 4 :
                return 4;
                break;
        }
    }

})

</script>        
		
		
    </body>
</html>
